﻿/***************************************************************************************/
// Author                 - Balaji Venkatesan
// Student ID             - 12527079
// Version                - 1.0
// CodeName               - Northodyne Solutions
// Module                 - E-Business Technologies
// Date                   - 12-September-2011
/***************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class AddSeminar : System.Web.UI.Page
{
    public string _connStr = "Initial Catalog=DBNorthodyneSolutions; Data Source=ABC\\SQLExpress;Trusted_Connection=Yes";
    public string _userName = string.Empty;

    public string _eventID = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        _userName = Session["UserName"].ToString();
        //lblUserName.Text = _userName;

        Label lblusername = (Label)Master.FindControl("lblUserName");
        HyperLink hyplogin = (HyperLink)Master.FindControl("hyplogin");
        lblusername.Text = _userName;
    }

    protected void btnAddSeminar_Click(object sender, EventArgs e)
    {
        using (SqlConnection connection = new SqlConnection(_connStr))
        {
            connection.Open();

            string propertyIDKey = "SELECT max(EventID) from Tb_Events";
            SqlCommand propertyIDCmd = new SqlCommand(propertyIDKey, connection);
            _eventID = Convert.ToString(propertyIDCmd.ExecuteScalar());

            int ActualPropertyID = Convert.ToInt32(_eventID.Substring(1));
            ActualPropertyID++;
            string resultantKey = "A" + ActualPropertyID;

            string insertSeminar = "INSERT INTO Tb_Events (EventID,EventName,Venue,Date,Time,Description) VALUES " + "(@EventID,@EventName,@Venue,@Date,@Time,@Description)";
            using (SqlCommand addseminarCmd = new SqlCommand(insertSeminar, connection))
            {
                SqlParameter[] prms = new SqlParameter[6];
                prms[0] = new SqlParameter("@EventID", SqlDbType.NVarChar, 50);
                prms[0].SqlValue = resultantKey;
                prms[1] = new SqlParameter("@EventName", SqlDbType.NVarChar, 50);
                prms[1].SqlValue = txtseminarName.Text.Trim();
                prms[2] = new SqlParameter("@Venue", SqlDbType.NVarChar, 50);
                prms[2].SqlValue = txtVenue.Text.Trim();

                prms[3] = new SqlParameter("@Date", SqlDbType.NVarChar,50);
                //ToDo - Debug this piece of code - Important!
                prms[3].SqlValue = calDate.SelectedDate.ToShortDateString();

                prms[4] = new SqlParameter("@Time", SqlDbType.NVarChar, 50);
                prms[4].SqlValue = ddlTime.SelectedItem.Text.Trim();
                prms[5] = new SqlParameter("@Description", SqlDbType.NVarChar, 50);
                prms[5].SqlValue = txtDescription.Text.Trim();

                addseminarCmd.Parameters.AddRange(prms);
                addseminarCmd.ExecuteNonQuery();
            }

            connection.Close();
        }

        Response.Redirect("AdminViewSeminar.aspx");
    }
}